<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('已结束任务列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>流程信息：</label>
                            <input type="text" name="keyInfo"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-auto-refresh="true" data-auto-refresh-interval="30"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-table-auto-refresh-js"/>
<script th:inline="javascript">
    var prefix = ctx + "busiflw/waittask";

    $(function () {
        var options = {
            url: prefix + "/closedTaskList",
            modalName: "待办任务",
            columns: [{
                checkbox: true
            },
                {
                    field: 'taskId',
                    title: '任务编号'
                },
                {
                    field: 'versionId',
                    title: '流程版本号',
                    visible: false
                },
                {
                    field: 'instanceId',
                    title: '业务编号',
                    formatter: function (value, row, index) {
                        var actions = '<a  href="javascript:void(0)" onclick="stepList(\'' + row.flowName + '\',\'' + row.versionId + '\',\'' + row.instanceId + '\')">' + row.instanceId + '</a>';
                        return actions;
                    }
                },
                {
                    field: 'flowName',
                    title: '流程名称'
                },
                {
                    field: 'createTime',
                    title: '开始时间'
                },
                {
                    field: 'stopTime',
                    title: '结束时间'
                },
                {
                    field: 'keyInfo',
                    halign: 'center',
                    title: '流程信息',
                    formatter: function (value, row, index) {
                        return getKeyInfo(row.keyInfo);
                    }
                },
                {
                    field: 'timeLimit',
                    title: '审批限时(小时)',
                    visible: false
                },
                {
                    field: 'waitTime',
                    title: '审批用时(小时)',
                    halign: 'center',
                    align: 'center'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="approveList(\'' + row.instanceId + '\')"><i class="fa fa-list-ul"></i>审批记录</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });


    /*流程信息json转标准页面格式*/
    function getKeyInfo(keyInfo) {
        const obj = JSON.parse(keyInfo);
        var keyInfoHtml = '<ul>'
        keyInfoHtml += '<li style = "text-align: left;" > 客户名称：';
        keyInfoHtml += '<span> ' + obj['cname'] + '</span>';
        keyInfoHtml += '</li>';
        keyInfoHtml += '</ul>';
        return keyInfoHtml;
    }

    //审批记录
    function approveList(instanceId) {
        $.modal.open("审批记录", ctx + "businessFlow/approveList/" + instanceId);
    }

    //审批步骤
    function stepList(flowName, versionId, instanceId) {
        var url = prefix + "/stepList/" + versionId + "/" + instanceId + "?flowName=" + flowName;
        $.modal.openTab(flowName + "审批步骤", encodeURI(url));
    }
</script>
</body>
</html>